// pages/incident_home_page/incident_home_page.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    winHeight: "",//窗口高度
    currentTab: 0, //预设当前项的值
    scrollLeft: 0, //tab标题的滚动条位置
    expertList: { //假数据
      "hot":[
        {
          "title": '11SJ-16846761546',
          "name":"管理员",
          "type":"服务器",
          "content":"内容",
          "time":"2018-08-16 18:31"
        },
        {
          "title": '22SJ-16846761546',
          "name": "管理员",
          "type": "服务器",
          "content": "内容",
          "time": "2018-08-16 18:31"
        },
        {
          "title": '33SJ-16846761546',
          "name": "管理员",
          "type": "服务器",
          "content": "内容",
          "time": "2018-08-16 18:31"
        },
        {
          "title": '44SJ-16846761546',
          "name": "管理员",
          "type": "服务器",
          "content": "内容",
          "time": "2018-08-16 18:31"
        },
        {
          "title": '55SJ-16846761546',
          "name": "管理员",
          "type": "服务器",
          "content": "内容",
          "time": "2018-08-16 18:31"
        }, {
          "title": '66SJ-16846761546',
          "name": "管理员",
          "type": "服务器",
          "content": "内容",
          "time": "2018-08-16 18:31"
        }, {
          "title": '77SJ-16846761546',
          "name": "管理员",
          "type": "服务器",
          "content": "内容",
          "time": "2018-08-16 18:31"
        }
      ],
      "my":[
        {
          "title": 'SJ-16846761546',
          "name": "管理员2",
          "type": "服务器",
          "content": "内容",
          "time": "2018-08-16 18:31"
        }
      ],
      "all":[
        {
          "title": 'SJ-16846761546',
          "name": "管理员3",
          "type": "服务器",
          "content": "内容",
          "time": "2018-08-16 18:31"
        }
      ]      

    },
    showView:false
 
  },
    //菜单监听
  onChangeShowState: function () {
    this.setData({
      showView: (!this.data.showView)
    })
  },
  // 滚动切换标签样式
  switchTab: function (e) {
    this.setData({
      currentTab: e.detail.current
    });
    this.checkCor();
  },
  // 点击标题切换当前页时改变样式
  swichNav: function (e) {
    var cur = e.target.dataset.current;
    if (this.data.currentTaB == cur) { return false; }
    else {
      this.setData({
        currentTab: cur
      })
    }
  },
  //判断当前滚动超过一屏时，设置tab标题滚动条。
  checkCor: function () {
    if (this.data.currentTab > 4) {
      this.setData({
        scrollLeft: 300
      })
    } else {
      this.setData({
        scrollLeft: 0
      })
    }
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //  高度自适应
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        /* var calc = clientHeight * rpxR - 180; */
        var calc = clientHeight * rpxR - 80; 
        console.log(calc)
        that.setData({
          winHeight: calc
        });
      }
    });

  },
  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //跳转到知识库内容页方法
  urlPath: function (res) {   //res点击内置属性
    let dataset = res.currentTarget.dataset;  //自定义data
    let title = dataset.title; 
    let url = "../login1/login1";  
    wx.navigateTo({
      url: url,
      data:{
        "title": title        
      },
      success:function(){
        console.log("知识库内容页跳转成功");
      }
    })
  },
  //上滚动加载
  lower: function () {
    wx.showLoading({
      title: '加载中',
    })
    let that = this;
    let hot = that.data.expertList.hot;
    let addData = [
      {
        "title": '88SJ-16846761546',
        "name": "管理员",
        "type": "服务器",
        "content": "内容",
        "time": "2018-08-16 18:31"
      }, {
        "title": '99SJ-16846761546',
        "name": "管理员",
        "type": "服务器",
        "content": "内容",
        "time": "2018-08-16 18:31"
      }, {
        "title": '1010SJ-16846761546',
        "name": "管理员",
        "type": "服务器",
        "content": "内容",
        "time": "2018-08-16 18:31"
      }
    ]
    console.log("hot", hot, "addData", addData)
    let allArray = hot.concat(addData);

    console.log("allArray", allArray)
    setTimeout(function () {
      wx.hideLoading()
    }, 2000)

    that.setData({
      expertList:{
        "hot": allArray
      }
    })
  }

})